package cn.tedu._05mvcboot01.controller;

import cn.tedu._05mvcboot01.pojo.dto.RegDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {
    /**
     * RequestMapping注解:根据请求的URL地址,将请求映射到对应的控制器的方法中;
     * ResponseBody注解:允许控制器方法以返回值的形式返回给客户端数据;
     * <p>
     * 1.GET请求：将username和password提交到服务器；
     * 浏览器地址栏中输入:
     * http://localhost:8080/v1/users/login?username=admin&password=123456
     */
    @RequestMapping("/v1/users/login")
    @ResponseBody
    public String login() {
        return "恭喜你，登录成功！";
    }

    /**
     * 注册功能
     * 1.通过服务端接收客户端闯过来的数据通过HttpServletRequest来接收
     *
     * @return
     */
    @RequestMapping("/v1/users/reg1")
    @ResponseBody
    public String reg1(HttpServletRequest request) {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String nickname = request.getParameter("nickname");
        return "username: "+username+" password: "+password+" nickname: "+nickname;
    }

    @RequestMapping("/v1/users/reg2")
    @ResponseBody
    public String reg2(String username,String password,String nickname) {
        return "username: "+username+" password: "+password+" nickname: "+nickname;
    }

    /**
     *参数数量少就用第二种多就用第三种
     */
    /*3.

     */
    @RequestMapping("/v1/users/reg3")
    @ResponseBody
    public String reg3(RegDTO regDTO) {
        String username=regDTO.getUsername();
        String password=regDTO.getPassword();
        String nickname=regDTO.getNickname();
        return "username: "+username+" password: "+password+" nickname: "+nickname;
    }
}
